// reading a text file
#include <iostream>
#include <string>
#include <vector>
#include "matriz.h"
#include "dfs.h"
#include "bfs.h"
#include "dijkstra.h"
#include "fecho.h"

using namespace std;

int main (int argc, char* argv[]) {
	//argumentos do programa
	if(argv[1] == NULL){
		std::cout << "usage: program filename first-node" << std::endl << "ex: grafos input.txt 0";
		return 0;
	}
	std::string filename;
	int startingNode;
	startingNode = atoi(argv[2]);
	filename = argv[1];

	//variaveis para output do dfs e bfs
	std::vector<int> dfsList;
	std::list<int> bfsList;
	std::list<int>::iterator bfsItr;
	std::vector<node> dijList;

	//lendo matriz do arquivo
	std::vector<std::vector<int> > matAdj;
	matAdj = matriz::getMatriz(filename);
	//matriz::printMatriz(matAdj);


	//rodando e exibindo dfs
	dfs dfsObj;
	dfsList = dfsObj.depthFirstSearch(matAdj,startingNode);
	std::cout  << "DFS = ";
	for(int x=0 ; (unsigned)x<dfsList.size() ; x++){
		std::cout << dfsList[x] << " ";
	}

	std::cout << std::endl;

	//rodando e exibindo bfs
	bfs bfsObj;
	bfsList = bfsObj.breadthFirstSearch(matAdj,startingNode);
	std::cout << "BFS = ";
	for(bfsItr=bfsList.begin() ; bfsItr!=bfsList.end() ; bfsItr++){
		std::cout << (*bfsItr) << " ";
	}

	std::cout << std::endl;

	//rodando e exibindo dijkstra
	dijkstra dijObj;
	dijList = dijObj.do_dijkstra(matAdj,startingNode);
	std::cout << "dijkstra = " << dijList[0].id+1 << "=" << dijList[0].antecessor+1 << std::endl;
	for(int x=1 ; (unsigned)x<dijList.size() ; x++){
		std::cout << "           " << dijList[x].id+1 << "=" << dijList[x].antecessor+1 << std::endl;
	}
//	std::cout << "dijkstra = " << dijList[0].id << "=" << dijList[0].antecessor << std::endl;
//	for(int x=1 ; (unsigned)x<dijList.size() ; x++){
//		std::cout << "           " << dijList[x].id << "=" << dijList[x].antecessor << std::endl;
//	}
/*
	std::cout << std::endl;

	//rodando e exibindo fecho
	fecho fechoObj;
	fechoObj.init(matAdj);
	fechoObj.fechoTransitivo(0);
	std::cout << "fecho = ";
	fechoObj.imprimeFecho();
*/
	return (0);
}
